package leetcodecompetition.D342;

import org.junit.jupiter.api.Test;
import tool.s;

import java.net.InetAddress;
import java.util.Arrays;
import java.util.PriorityQueue;

public class T6390 {
    public int[] getSubarrayBeauty(int[] nums, int k, int x) {
        final int b = 50;
        int n = nums.length;
        int[] res = new int[n-k+1];
        int[] cnt = new int[2 * b + 1];
        for (int i = 0; i < k-1; i++) {
            cnt[nums[i] + b]++;
        }
        for (int i = k-1; i < n; i++) {
            cnt[nums[i] + b]++;
            int sum=0;
            for (int j = 0; j <b ; j++) {
                sum+=cnt[j];
                if (sum>=x){
                    res[i-k+1]=j-b;
                    break;
                }
            }
            cnt[nums[i-k+1]+b]--;
        }
        return res;
    }


    @Test
    public void test() {
        int[] a = {1, -1, -3, -2, 3};
        s.print(getSubarrayBeauty(a, 3, 2));

    }

}
